package com.inspur.gs.sbssdl.sbssbxgl.sbssbx.sbssbx.front.sbssbxfirstform_frm.voactions;
import com.inspur.edp.bef.api.lcp.ILcpFactory;
import com.inspur.edp.bef.api.lcp.IStandardLcp;
import com.inspur.edp.bef.api.services.IBefSessionManager;
import com.inspur.edp.cef.entity.condition.EntityFilter;
import com.inspur.edp.cef.entity.condition.FilterCondition;
import com.inspur.edp.cef.entity.condition.FilterConditionBuilder;
import com.inspur.edp.cef.entity.entity.IEntityData;
import com.inspur.edp.web.help.api.LookupQueryParam;
import com.inspur.edp.bff.spi.*;
import com.inspur.edp.bef.api.action.*;
import io.iec.edp.caf.commons.utils.SpringBeanUtils;

import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;

public class gzdhelpbeforeVOAction extends AbstractHelpAction {

	public gzdhelpbeforeVOAction() {

	}
	private static String sbbxid = "c5fd08f7-6410-4d7c-b662-693f94fde569";
	@Override
	public
	void beforeHelp(LookupQueryParam lookupQueryParam) {
		//故障单帮助前过滤保修单已经选过的故障单
		SpringBeanUtils.getBean(IBefSessionManager.class).createSession();
		try {
			ILcpFactory iLcpFactory = SpringBeanUtils.getBean(ILcpFactory.class);
			//设备台账的变更
			IStandardLcp lcp = iLcpFactory.createLcpByBEId(sbbxid);
			EntityFilter filter = new EntityFilter();
			ArrayList<FilterCondition> filterConditions = (ArrayList<FilterCondition>) FilterConditionBuilder
					.builder()
					.andNotEqual("BillStatus", "0")
					.build();
			filter.addFilterConditions(filterConditions);
			List<String> gzdbhlist = lcp.query(filter).stream().map(s -> s.getValue("gzdbh").toString()).collect(Collectors.toList());

			//过滤
			EntityFilter gzdfilter = new EntityFilter();
			ArrayList<FilterCondition> gzdfilterConditions = (ArrayList<FilterCondition>) FilterConditionBuilder.builder().andNotIn("Gzdh", gzdbhlist).build();
			gzdfilter.addFilterConditions(gzdfilterConditions);
			lookupQueryParam.setFilter(gzdfilter);
		} finally {
			SpringBeanUtils.getBean(IBefSessionManager.class).closeCurrentSession();
		}
	}
}
